/*=========================================================================
The Impact of Denying a Wanted Abortion on Women and Children
Authors: Juliana Londoño-Vélez and Estefanía Saravia

Creation date: January 9th, 2024
--------------------------------------------------------------------------
Table 10 - The Impact of Being Denied a Wanted Abortion on Women's Existing Children
=========================================================================*/

use "$data/Final_Medellin_Children.dta", replace

	
global outcomes Estudia Inasistencia_Escolar Rezago_Escolar Trabajo_Infantil Cuidado_1 Cuidado_2 Cuidado_5 Cuidado_6 Cuidado_7
	

	
mat a=J(9,3,.)
matrix rownames a =  $outcomes


local i=1
foreach var in $outcomes    {


	sum `var' if Niega==0 & ultimo_hijo==1
	mat 	a[`i',1] = r(mean)

	ivreghdfe `var'         (Niega=Mujer_Ponente)  if ultimo_hijo==1, abs(oficina#time) cluster(id_juez) savefirst

	mat 	a[`i',2]  = _b[Niega]
	mat 	a[`i',3] = _se[Niega]

		
	local i=`i'+1

	}


mat lis a

	svmat2 a, rnames(outcome)
	
	drop if outcome==""
	
	rename a1 mean_nondenied
	rename a2 coef_femaleIV
	rename a3 se_femaleIV

	
	
	keep outcome mean_nondenied coef_femaleIV se_femaleIV
	
	order outcome mean_nondenied coef_femaleIV se_femaleIV


	export excel using "$output/Tables paper matrices replication.xlsx", sheet("Table 10", modify) 
